package com.bac.rentmap.ad.flat.image;

import java.util.Date;
import java.util.List;

import javax.jdo.PersistenceManager;

import com.bac.rentmap.ad.flat.FlatAd;
import com.bac.rentmap.ad.flat.crawler.FlatCrawledAd;
import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.datastore.Key;

public interface FlatImageService {
    FlatImage upload(FlatImageType imageType, String sessionId,
            BlobKey imageBlob) throws UnsupportedImageTypeException;

    void delete(FlatImageType imageType, String sessionId);
    void delete(FlatImageType imageType, String sessionId, PersistenceManager persistenceManager);

    void attachToFlatCrawledAd(String sessionId, FlatCrawledAd flatCrawledAd);

    void updateFlatAdImages(String sessionId,
                                   FlatAd flatAd);

    void attachToFlatAd(long flatCrawledAdId, long flatAdId, Date publishingDate);

    FlatImage getUploadedImage(String sessionId, FlatImageType flatImageType);

    FlatImage getFlatImage(long id);

    /**
     * Get images for flat crawled ad or for flat ad.
     *
     * @param key of {@link FlatCrawledAd} or {@link FlatAd}.
     * @return not null list of flat image ids
     */
    List<Long> getFlatImageIds(Key key, PersistenceManager persistenceManager);

    List<FlatImage> getFlatImages(Key key, PersistenceManager persistenceManager);

    // TODO move to JdoFlatImageService
    void deleteAll(long flatAdId, PersistenceManager persistenceManager);
    void deleteAll(String sessionId, PersistenceManager persistenceManager);

    void updatePublishingDate(FlatAd flatAd,
            PersistenceManager persistenceManager);
}
